package org.sgx.gapigui.client.ui.editableModels.youtube;

import org.sgx.gapi.client.apis.urlshortener.UrlResource;
import org.sgx.gapi.client.apis.urlshortener.UrlResourceBean;
import org.sgx.gapi.client.apis.youtube.Search;
import org.sgx.gapi.client.apis.youtube.SearchSnippet;
import org.sgx.gapi.client.apis.youtube.SearchSnippetThumbnail;
import org.sgx.gapigui.client.ui.editableModels.urlShortener.Url;
import org.sgx.gwteditors.client.impl1.edbean.EditableBean;
import org.sgx.gwteditors.client.impl1.edbean.UseEditor;
import org.sgx.jsutil.client.JsUtil;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JsArrayString;

public abstract class Video implements EditableBean {
String title, description, url, image;

public static Video from(Search s) {
	Video v = GWT.create(Video.class);
	v.setTitle(s.snippet().title()); 
	v.setDescription(s.snippet().description()); 
	v.setUrl("http://www.youtube.com/watch?v="+s.id().videoId()); 
	
	JsArrayString thumbNames = s.snippet().thumbnails().objProps();
	if(thumbNames!=null && thumbNames.length()>0) {
		SearchSnippetThumbnail thumbNail = s.snippet().thumbnail(thumbNames.get(0)); 
		v.setImage(thumbNail.url()); 
	}		
	return v;
}

public String getTitle() {
	return title;
}

public void setTitle(String title) {
	this.title = title;
}

public String getDescription() {
	return description;
}

public void setDescription(String description) {
	this.description = description;
}
@UseEditor(
		description="Youtube Video Url", 
		editorName="org.sgx.gwteditors.client.impl1.misc.LinkEditor", 
		label="whatch it on youtube")
public String getUrl() {
	return url;
}

public void setUrl(String url) {
	this.url = url;
}

@UseEditor(
		description="Video image", 
		editorName="org.sgx.gwteditors.client.impl1.misc.ImageUrlEditor", 
		label="Image", 
		config="height: '50px'") 
public String getImage() {
	return image;
}

public void setImage(String image) {
	this.image = image;
}

}
